package edu.unf.cen6940.web;

import edu.unf.cen6940.dao.UserloginDAO;

import edu.unf.cen6940.domain.Userlogin;

import edu.unf.cen6940.service.UserloginService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Userlogin entities
 * 
 */

@Controller("UserloginController")
public class UserloginController {

	/**
	 * DAO injected by Spring that manages Userlogin entities
	 * 
	 */
	@Autowired
	private UserloginDAO userloginDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Userlogin entities
	 * 
	 */
	@Autowired
	private UserloginService userloginService;

	/**
	 * Select the Userlogin entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteUserlogin")
	public ModelAndView confirmDeleteUserlogin(@RequestParam Integer userLoginIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("userlogin", userloginDAO.findUserloginByPrimaryKey(userLoginIdKey));
		mav.setViewName("userlogin/deleteUserlogin.jsp");

		return mav;
	}

	/**
	 */
	@RequestMapping("/userloginController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * Show all Userlogin entities
	 * 
	 */
	@RequestMapping("/indexUserlogin")
	public ModelAndView listUserlogins() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("userlogins", userloginService.loadUserlogins());

		mav.setViewName("userlogin/listUserlogins.jsp");

		return mav;
	}

	/**
	 * Save an existing Userlogin entity
	 * 
	 */
	@RequestMapping("/saveUserlogin")
	public String saveUserlogin(@ModelAttribute Userlogin userlogin) {
		userloginService.saveUserlogin(userlogin);
		return "forward:/indexUserlogin";
	}

	/**
	 * Select an existing Userlogin entity
	 * 
	 */
	@RequestMapping("/selectUserlogin")
	public ModelAndView selectUserlogin(@RequestParam Integer userLoginIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("userlogin", userloginDAO.findUserloginByPrimaryKey(userLoginIdKey));
		mav.setViewName("userlogin/viewUserlogin.jsp");

		return mav;
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Delete an existing Userlogin entity
	 * 
	 */
	@RequestMapping("/deleteUserlogin")
	public String deleteUserlogin(@RequestParam Integer userLoginIdKey) {
		Userlogin userlogin = userloginDAO.findUserloginByPrimaryKey(userLoginIdKey);
		userloginService.deleteUserlogin(userlogin);
		return "forward:/indexUserlogin";
	}

	/**
	 * Entry point to show all Userlogin entities
	 * 
	 */
	public String indexUserlogin() {
		return "redirect:/indexUserlogin";
	}

	/**
	 * Edit an existing Userlogin entity
	 * 
	 */
	@RequestMapping("/editUserlogin")
	public ModelAndView editUserlogin(@RequestParam Integer userLoginIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("userlogin", userloginDAO.findUserloginByPrimaryKey(userLoginIdKey));
		mav.setViewName("userlogin/editUserlogin.jsp");

		return mav;
	}

	/**
	 * Create a new Userlogin entity
	 * 
	 */
	@RequestMapping("/newUserlogin")
	public ModelAndView newUserlogin() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("userlogin", new Userlogin());
		mav.addObject("newFlag", true);
		mav.setViewName("userlogin/editUserlogin.jsp");

		return mav;
	}
}